package com.xjrsoft.module.workflow.listener;


import com.alibaba.fastjson.JSONArray;
import com.xjrsoft.core.tool.utils.StringPool;
import lombok.extern.slf4j.Slf4j;
import org.flowable.bpmn.model.CallActivity;
import org.flowable.bpmn.model.FlowElement;
import org.flowable.bpmn.model.SequenceFlow;
import org.flowable.engine.delegate.DelegateExecution;
import org.flowable.engine.delegate.ExecutionListener;
import org.springframework.stereotype.Component;

//流程流转监听 (会签任务)
@Slf4j
@Component
public class TakeListener implements ExecutionListener {


    @Override
    public void notify(DelegateExecution execution) {
        SequenceFlow currentFlowElement = (SequenceFlow) execution.getCurrentFlowElement();
        //获取流程线目标id
        String targetRef = currentFlowElement.getTargetRef();
        JSONArray jsonArray = new JSONArray();
        FlowElement targetFlowElement = currentFlowElement.getTargetFlowElement();
        if(!(targetFlowElement instanceof CallActivity)){
            //不为外部流程为普通用户任务
            jsonArray.add("xxx");
            execution.setVariable(targetRef+ StringPool.UNDERSCORE+"usernamelist",jsonArray);
        }
        execution.setVariable("completeCount", 0);
    }
}
